package cn.dugcrs.org.controller;

import cn.dugcrs.basic.utils.AjaxResult;
import cn.dugcrs.basic.utils.QueryResult;
import cn.dugcrs.org.domain.Systemdictionarytype;
import cn.dugcrs.org.query.DetailQuery;
import cn.dugcrs.org.query.TypeQuery;
import cn.dugcrs.org.service.IDetailService;
import cn.dugcrs.org.service.ITypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
@Api(value = "店铺的API",description="店铺相关的CRUD功能")
public class SystemdictionarytypeController {

    @Autowired
    private ITypeService typeService;

    /*
    * @Title: findSystemdictionarytypeById
    * @Description: 查询单条数据
    * @Author: Gubcog
    * @Version: 1.0
    * @Date:  2022/4/22 13:13
    * @Parameters: * @param id
    * @Return cn.dugcrs.org.domain.Systemdictionarytype
    */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public Systemdictionarytype findSystemdictionarytypeById(@ApiParam(name="ID属性",required = true)@PathVariable("id") Long id){
        Systemdictionarytype typeById = typeService.loadById(id);
        return typeById;
    }

    /*
    * @Title: findSystemdictionarytypes
    * @Description: 查询符合高级查询条件及分页的全部数据
    * @Author: Gubcog
    * @Version: 1.0
    * @Date:  2022/4/22 13:14
    * @Parameters: * @param typeQuery
    * @Return cn.dugcrs.basic.utils.QueryResult
    */
    @PostMapping
    public QueryResult findSystemdictionarytypes(@RequestBody TypeQuery typeQuery){
        System.out.println("===========");
        QueryResult types = typeService.queryPage(typeQuery);
        return types;
    }

    /**
    * @Title: findSystemdictionarytypes
    * @Description: 查询所有
    * @Author: Gubcog
    * @Version: 1.0
    * @Date:  2022/4/24 14:34
    * @Parameters: * @param
    * @Return java.util.List<cn.dugcrs.org.domain.Systemdictionarytype>
    */
    @GetMapping
    public List<Systemdictionarytype> findSystemdictionarytypes(){
        List<Systemdictionarytype> types = typeService.loadAll();
        return types;
    }

    /*
    * @Title: findSystemdictionarytypes
    * @Description: 根据id删除
    * @Author: Gubcog
    * @Version: 1.0
    * @Date:  2022/4/22 13:20
    * @Parameters: * @param id
    * @Return cn.dugcrs.basic.utils.AjaxResult
    */
    @DeleteMapping("/{id}")
    public AjaxResult delSystemdictionarytypeById(@PathVariable("id") Long id){
        try {
            typeService.remove(id);
            return AjaxResult.success();
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }

    /*
    * @Title: addOrUpd
    * @Description: 添加或修改
    * @Author: Gubcog
    * @Version: 1.0
    * @Date:  2022/4/22 13:55
    * @Parameters: * @param type
    * @Return cn.dugcrs.basic.utils.AjaxResult
    */
    @PutMapping
    public AjaxResult addOrUpd(@RequestBody Systemdictionarytype type){
        try {
            if (type.getId() == null){
                typeService.save(type);
            } else {
                typeService.update(type);
            }
            return AjaxResult.success();
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }

    @PatchMapping
    public AjaxResult batchDelDept(@RequestBody List<Long> ids){
        try {
            typeService.batchRemove(ids);
            return AjaxResult.success();
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }


}
